/*
 * Copyright (C) Michael Opitz
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
 * USA
 */
#ifndef CONNECTION_LISTENER_H
#define CONNECTION_LISTENER_H

#include <boost/shared_ptr.hpp>

#include "worker_thread.h"
#include "tcp_socket.h"
#include "network.h"
//#include "event_handler.h"

/** 
 * \brief This namespaces includes all nertwork related stuff.
 * \author Michael Opitz
 */
namespace network {
	/** 
	 * This class provides a server-socket functionality. It runs as a
	 * thread and listenes to a specific tcp-port. If a connection is
	 * established it is inserted in the message_queue, with the established
	 * socket.
	 * \brief this class provides a server-socket functionality.
	 */
	class connection_listener : public network::worker_thread {
	public:
		/** 
		 * \brief connection_listener is the constructor for the
		 * connection_listener class.
		 * 
		 * \param sock is the socket from which connection_listener
		 * should listen.
		 * \param q is the message_queue into which the
		 * connection_listener should insert his messages.
		 */
		connection_listener(boost::shared_ptr<network::tcp_socket> sock,
				    boost::shared_ptr<network::message_queue> q)
		: _sock(sock), _queue(q) {}
		virtual ~connection_listener();

		/** 
		 * \brief run runs the thread. Don't call this method, and use
		 * start_thread() instead.
		 * \see network::worker_thread
		 */
		virtual void run();
	private:
		boost::shared_ptr<network::tcp_socket> _sock;
		boost::shared_ptr<network::message_queue> _queue;
	};
}

#endif
